package com.ddwl.goods.dao;

import com.ddwl.common.dao.TkDao;
import com.ddwl.common.util.MySqlUtil;
import com.ddwl.goods.mapper.SignHistMapper;
import com.ddwl.goods.model.SignHist;
import com.ddwl.schema.bo.goods.SignHistBo;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author hemiaojun
 * @Date 2020/10/20 15:43
 */
@Repository
public class SignHistDao extends TkDao<SignHistMapper, SignHist> {

    @Resource
    private SignHistMapper signHistMapper;

    public List<SignHist> getList(SignHistBo bo) {
        Example example=getExample();
        example.and().andEqualTo("userId", bo.getUserId())
                .andLike("mobile", MySqlUtil.rightLike(bo.getMobile()))
                .andLike("userName", MySqlUtil.rightLike(bo.getUserName()));
        return signHistMapper.selectByExample(example);
    }

    public List<SignHist> getThisWeek(String userId, List<String> weekDate) {
        Example example=getExample();
        example.and().andEqualTo("userId", userId)
                .andIn("signDate", weekDate);
        return signHistMapper.selectByExample(example);
    }

    public SignHist getByUserIdAndSignDate(String userId,String weekDate) {
        Example example=getExample();
        example.and().andEqualTo("userId", userId)
                .andEqualTo("signDate", weekDate);
        return signHistMapper.selectOneByExample(example);
    }
}
